#coding: utf-8
#for python3.6.5

import PyQt5 as QT
from PyQt5 import QtCore, QtWidgets, QtGui
import random

import os,sys,xlrd
import numpy as np
import math
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as pltCanvas
from matplotlib.backends.backend_qt5 import NavigationToolbar2QT as pltToolbar
import matplotlib.pyplot as plt

class Class1(QtWidgets.QDialog):
    def __init__(self):
        super().__init__()
        self.resize(1200, 600)
        self.func()
        self.channel = 0

    def func(self):
        main_layout = QtWidgets.QVBoxLayout()

        layout = QtWidgets.QHBoxLayout()  # layout for the central widget

        widget = QtWidgets.QWidget(self)  # central widget
        widget.setLayout(layout)

        self.number_group = QtWidgets.QButtonGroup(widget)  # Number group
        self.r0 = QtWidgets.QRadioButton("0通道")
        self.number_group.addButton(self.r0, 0)
        self.r1 = QtWidgets.QRadioButton("1通道")
        self.number_group.addButton(self.r1, 1)
        self.r0.toggled.connect(self._NoSel)
        self.r1.toggled.connect(self._NoSel)

        self.r0.setChecked(True)

        layout.addWidget(self.r0)
        layout.addWidget(self.r1)

        self.letter_group = QtWidgets.QButtonGroup(widget)  # Letter group
        ra = QtWidgets.QRadioButton("a")
        self.letter_group.addButton(ra)
        rb = QtWidgets.QRadioButton("b")
        self.letter_group.addButton(rb)
        layout.addWidget(ra)
        layout.addWidget(rb)

        layout.addStretch(1)

        # plt layout
        self.fig = plt.figure()
        self.ax = self.fig.add_subplot(1, 1, 1)
        qw2 = QtWidgets.QWidget(self)
        pltlayout = QtWidgets.QVBoxLayout()
        qw2.setLayout(pltlayout)

        self.canvas = pltCanvas(self.fig)
        self.toolbar = pltToolbar(self.canvas, self)

        pltlayout.addWidget(self.toolbar)
        pltlayout.addWidget(self.canvas)

        main_layout.addWidget(widget)
        main_layout.addWidget(qw2)
        self.setLayout(main_layout)

    def _NoSel(self):
        if self.r0.isChecked():
            self.channel = 0
        if self.r1.isChecked():
            self.channel = 1
        print("checked {0}, channel={1}".format(self.number_group.checkedId(), self.channel))

        # assign the widget to the main window
        #self.setCentralWidget(widget)
        #self.show()

def main():
    app = QtWidgets.QApplication(sys.argv)
    mw = Class1()
    mw.show()
    sys.exit(app.exec_())


if __name__=='__main__':
    main()